from typing import Union
from fastapi import FastAPI

import wenxin_api  # 可以通过"pip install wenxin-api"命令安装
from wenxin_api.tasks.composition import Composition
wenxin_api.ak = "Fz3NjB25nGMMbvRnI3MgG189NDgLf7ya"
wenxin_api.sk = "nWpBySPdDH6XHPGBrU1GIGSynITY7SyQ"

app = FastAPI()

@app.get("/r/{item_title}")
def read_centont(item_title: str):
    input_dict = {
        "text": "标题：" + item_title + "\n正文：",
        "seq_len": 812,
        "topp": 0.9,
        "penalty_score": 1.2,
        "min_dec_len": 128,
        "is_unidirectional": 0,
        "task_prompt": "PARAGRAPH"
    }
    rst = Composition.create(**input_dict)
    return rst

